<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="orderSn">
        <el-input
          v-model="queryParams.orderSn"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付id" prop="payId">
        <el-input
          v-model="queryParams.payId"
          placeholder="请输入支付id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户帐号" prop="memberUsername">
        <el-input
          v-model="queryParams.memberUsername"
          placeholder="请输入用户帐号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单总金额" prop="totalAmount">
        <el-input
          v-model="queryParams.totalAmount"
          placeholder="请输入订单总金额"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购价" prop="purchasePrice">
        <el-input
          v-model="queryParams.purchasePrice"
          placeholder="请输入采购价"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应付金额" prop="payAmount">
        <el-input
          v-model="queryParams.payAmount"
          placeholder="请输入应付金额"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运费金额" prop="freightAmount">
        <el-input
          v-model="queryParams.freightAmount"
          placeholder="请输入运费金额"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式" clearable>
          <el-option
            v-for="dict in oms_pay_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable >
          <el-option
            v-for="dict in oms_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"

          />
        </el-select>
      </el-form-item>
      <el-form-item label="退款状态" prop="aftersaleStatus">
        <el-select v-model="queryParams.aftersaleStatus" placeholder="请选择退款状态" clearable>
          <el-option
            v-for="dict in oms_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="物流公司" prop="deliveryCompany">
        <el-input
          v-model="queryParams.deliveryCompany"
          placeholder="请输入物流公司"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物流单号" prop="deliverySn">
        <el-input
          v-model="queryParams.deliverySn"
          placeholder="请输入物流单号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确认时间" prop="autoConfirmDay">
        <el-input
          v-model="queryParams.autoConfirmDay"
          placeholder="请输入自动确认时间"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货姓名" prop="receiverName">
        <el-input
          v-model="queryParams.receiverName"
          placeholder="请输入收货人姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货电话" prop="receiverPhone">
        <el-input
          v-model="queryParams.receiverPhone"
          placeholder="请输入收货人电话"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货邮编" prop="receiverPostCode">
        <el-input
          v-model="queryParams.receiverPostCode"
          placeholder="请输入收货人邮编"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="receiverDetailAddress">
        <el-input
          v-model="queryParams.receiverDetailAddress"
          placeholder="请输入详细地址"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货状态" prop="confirmStatus">
        <el-select v-model="queryParams.confirmStatus" placeholder="请选择确认收货状态：0->未确认；1->已确认" clearable>
          <el-option
            v-for="dict in oms_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="删除状态" prop="deleteStatus">
        <el-select v-model="queryParams.deleteStatus" placeholder="请选择删除状态：0->未删除；1->已删除" clearable>
          <el-option
            v-for="dict in sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付时间" style="width: 308px">
        <el-date-picker
          v-model="daterangePaymentTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="发货时间" style="width: 308px">
        <el-date-picker
          v-model="daterangeDeliveryTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="确认收货时间" style="width: 308px">
        <el-date-picker
          v-model="daterangeReceiveTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['oms:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['oms:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['oms:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['oms:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id" align="center" prop="id" v-if="false"/>
      <el-table-column label="订单编号" align="center" prop="orderSn" />
      <el-table-column label="支付id" align="center" prop="payId" />
      <el-table-column label="用户帐号" align="center" prop="memberUsername" />
      <el-table-column label="总金额" align="center" prop="totalAmount" />
      <el-table-column label="采购价" align="center" prop="purchasePrice" />
      <el-table-column label="应付金额" align="center" prop="payAmount" />
      <el-table-column label="运费金额" align="center" prop="freightAmount" />
      <el-table-column label="支付方式" align="center" prop="payType">
        <template #default="scope">
          <dict-tag :options="oms_pay_type" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="oms_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="退款状态" align="center" prop="aftersaleStatus">
        <template #default="scope">
          <dict-tag :options="oms_order_status" :value="scope.row.aftersaleStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="物流公司" align="center" prop="deliveryCompany" />
      <el-table-column label="物流单号" align="center" prop="deliverySn" />
      <el-table-column label="收货姓名" align="center" prop="receiverName" />
      <el-table-column label="收货电话" align="center" prop="receiverPhone" />
      <el-table-column label="收货邮编" align="center" prop="receiverPostCode" />
      <el-table-column label="详细地址" align="center" prop="receiverDetailAddress" />
      <el-table-column label="确认时间" align="center" prop="autoConfirmDay" />
      <el-table-column label="收货状态" align="center" prop="confirmStatus">
        <template #default="scope">
          <dict-tag :options="oms_order_status" :value="scope.row.confirmStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="删除状态" align="center" prop="deleteStatus">
        <template #default="scope">
          <dict-tag :options="sys_common_status" :value="scope.row.deleteStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="paymentTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发货时间" align="center" prop="deliveryTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="确认收货时间" align="center" prop="receiveTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.receiveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['oms:order:edit']">修改</el-button>
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['oms:order:remove']">删除</el-button>
          </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单管理对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="orderRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderSn">
          <el-input v-model="form.orderSn" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="支付id" prop="payId">
          <el-input v-model="form.payId" placeholder="请输入支付id" />
        </el-form-item>
        <el-form-item label="会员id" prop="memberId">
          <el-input v-model="form.memberId" placeholder="请输入会员id" />
        </el-form-item>
        <el-form-item label="用户帐号" prop="memberUsername">
          <el-input v-model="form.memberUsername" placeholder="请输入用户帐号" />
        </el-form-item>
        <el-form-item label="订单总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入订单总金额" />
        </el-form-item>
        <el-form-item label="采购价" prop="purchasePrice">
          <el-input v-model="form.purchasePrice" placeholder="请输入采购价" />
        </el-form-item>
        <el-form-item label="应付金额" prop="payAmount">
          <el-input v-model="form.payAmount" placeholder="请输入应付金额" />
        </el-form-item>
        <el-form-item label="运费金额" prop="freightAmount">
          <el-input v-model="form.freightAmount" placeholder="请输入运费金额" />
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
          <el-radio-group v-model="form.payType">
            <el-radio
              v-for="dict in oms_pay_type"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in oms_order_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="退款状态" prop="aftersaleStatus">
          <el-radio-group v-model="form.aftersaleStatus">
            <el-radio
              v-for="dict in oms_order_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="物流公司" prop="deliveryCompany">
          <el-input v-model="form.deliveryCompany" placeholder="请输入物流公司" />
        </el-form-item>
        <el-form-item label="物流单号" prop="deliverySn">
          <el-input v-model="form.deliverySn" placeholder="请输入物流单号" />
        </el-form-item>
        <el-form-item label="自动确认时间" prop="autoConfirmDay">
          <el-input v-model="form.autoConfirmDay" placeholder="请输入自动确认时间" />
        </el-form-item>
        <el-form-item label="收货人姓名" prop="receiverName">
          <el-input v-model="form.receiverName" placeholder="请输入收货人姓名" />
        </el-form-item>
        <el-form-item label="收货人电话" prop="receiverPhone">
          <el-input v-model="form.receiverPhone" placeholder="请输入收货人电话" />
        </el-form-item>
        <el-form-item label="收货人邮编" prop="receiverPostCode">
          <el-input v-model="form.receiverPostCode" placeholder="请输入收货人邮编" />
        </el-form-item>
        <el-form-item label="省份/直辖市" prop="receiverProvince">
          <el-input v-model="form.receiverProvince" placeholder="请输入省份/直辖市" />
        </el-form-item>
        <el-form-item label="城市" prop="receiverCity">
          <el-input v-model="form.receiverCity" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="区" prop="receiverDistrict">
          <el-input v-model="form.receiverDistrict" placeholder="请输入区" />
        </el-form-item>
        <el-form-item label="省份/直辖市id" prop="receiverProvinceId">
          <el-input v-model="form.receiverProvinceId" placeholder="请输入省份/直辖市id" />
        </el-form-item>
        <el-form-item label="城市id" prop="receiverCityId">
          <el-input v-model="form.receiverCityId" placeholder="请输入城市id" />
        </el-form-item>
        <el-form-item label="区id" prop="receiverDistrictId">
          <el-input v-model="form.receiverDistrictId" placeholder="请输入区id" />
        </el-form-item>
        <el-form-item label="详细地址" prop="receiverDetailAddress">
          <el-input v-model="form.receiverDetailAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="订单备注" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="商家备注" prop="merchantNote">
          <el-input v-model="form.merchantNote" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="确认收货状态：0->未确认；1->已确认" prop="confirmStatus">
          <el-radio-group v-model="form.confirmStatus">
            <el-radio
              v-for="dict in oms_order_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除状态：0->未删除；1->已删除" prop="deleteStatus">
          <el-radio-group v-model="form.deleteStatus">
            <el-radio
              v-for="dict in sys_common_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="支付时间" prop="paymentTime">
          <el-date-picker clearable
            v-model="form.paymentTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发货时间" prop="deliveryTime">
          <el-date-picker clearable
            v-model="form.deliveryTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择发货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="确认收货时间" prop="receiveTime">
          <el-date-picker clearable
            v-model="form.receiveTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择确认收货时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Order">
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/oms/order";

const { proxy } = getCurrentInstance();
const { oms_pay_type, sys_common_status, oms_order_status } = proxy.useDict('oms_pay_type', 'sys_common_status', 'oms_order_status');

const orderList = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangePaymentTime = ref([]);
const daterangeDeliveryTime = ref([]);
const daterangeReceiveTime = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    orderSn: undefined,
    payId: undefined,
    memberId: undefined,
    memberUsername: undefined,
    totalAmount: undefined,
    purchasePrice: undefined,
    payAmount: undefined,
    freightAmount: undefined,
    payType: undefined,
    status: undefined,
    aftersaleStatus: undefined,
    deliveryCompany: undefined,
    deliverySn: undefined,
    autoConfirmDay: undefined,
    receiverName: undefined,
    receiverPhone: undefined,
    receiverPostCode: undefined,
    receiverProvince: undefined,
    receiverCity: undefined,
    receiverDistrict: undefined,
    receiverProvinceId: undefined,
    receiverCityId: undefined,
    receiverDistrictId: undefined,
    receiverDetailAddress: undefined,
    note: undefined,
    merchantNote: undefined,
    confirmStatus: undefined,
    deleteStatus: undefined,
    paymentTime: undefined,
    deliveryTime: undefined,
    receiveTime: undefined,
  },
  rules: {
    id: [
      { required: true, message: "订单id不能为空", trigger: "blur" }
    ],
    orderSn: [
      { required: true, message: "订单编号不能为空", trigger: "blur" }
    ],
    payId: [
      { required: true, message: "支付id不能为空", trigger: "blur" }
    ],
    memberId: [
      { required: true, message: "会员id不能为空", trigger: "blur" }
    ],
    memberUsername: [
      { required: true, message: "用户帐号不能为空", trigger: "blur" }
    ],
    totalAmount: [
      { required: true, message: "订单总金额不能为空", trigger: "blur" }
    ],
    purchasePrice: [
      { required: true, message: "采购价不能为空", trigger: "blur" }
    ],
    payAmount: [
      { required: true, message: "应付金额不能为空", trigger: "blur" }
    ],
    freightAmount: [
      { required: true, message: "运费金额不能为空", trigger: "blur" }
    ],
    payType: [
      { required: true, message: "支付方式不能为空", trigger: "change" }
    ],
    status: [
      { required: true, message: "订单状态不能为空", trigger: "change" }
    ],
    aftersaleStatus: [
      { required: true, message: "退款状态不能为空", trigger: "change" }
    ],
    deliveryCompany: [
      { required: true, message: "物流公司不能为空", trigger: "blur" }
    ],
    deliverySn: [
      { required: true, message: "物流单号不能为空", trigger: "blur" }
    ],
    autoConfirmDay: [
      { required: true, message: "自动确认时间不能为空", trigger: "blur" }
    ],
    receiverName: [
      { required: true, message: "收货人姓名不能为空", trigger: "blur" }
    ],
    receiverPhone: [
      { required: true, message: "收货人电话不能为空", trigger: "blur" }
    ],
    receiverPostCode: [
      { required: true, message: "收货人邮编不能为空", trigger: "blur" }
    ],
    receiverProvince: [
      { required: true, message: "省份/直辖市不能为空", trigger: "blur" }
    ],
    receiverCity: [
      { required: true, message: "城市不能为空", trigger: "blur" }
    ],
    receiverDistrict: [
      { required: true, message: "区不能为空", trigger: "blur" }
    ],
    receiverProvinceId: [
      { required: true, message: "省份/直辖市id不能为空", trigger: "blur" }
    ],
    receiverCityId: [
      { required: true, message: "城市id不能为空", trigger: "blur" }
    ],
    receiverDistrictId: [
      { required: true, message: "区id不能为空", trigger: "blur" }
    ],
    receiverDetailAddress: [
      { required: true, message: "详细地址不能为空", trigger: "blur" }
    ],
    note: [
      { required: true, message: "订单备注不能为空", trigger: "blur" }
    ],
    merchantNote: [
      { required: true, message: "商家备注不能为空", trigger: "blur" }
    ],
    confirmStatus: [
      { required: true, message: "确认收货状态：0->未确认；1->已确认不能为空", trigger: "change" }
    ],
    deleteStatus: [
      { required: true, message: "删除状态：0->未删除；1->已删除不能为空", trigger: "change" }
    ],
    paymentTime: [
      { required: true, message: "支付时间不能为空", trigger: "blur" }
    ],
    deliveryTime: [
      { required: true, message: "发货时间不能为空", trigger: "blur" }
    ],
    receiveTime: [
      { required: true, message: "确认收货时间不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询订单管理列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangePaymentTime && '' != daterangePaymentTime) {
    queryParams.value.params["beginPaymentTime"] = daterangePaymentTime.value[0];
    queryParams.value.params["endPaymentTime"] = daterangePaymentTime.value[1];
  }
  if (null != daterangeDeliveryTime && '' != daterangeDeliveryTime) {
    queryParams.value.params["beginDeliveryTime"] = daterangeDeliveryTime.value[0];
    queryParams.value.params["endDeliveryTime"] = daterangeDeliveryTime.value[1];
  }
  if (null != daterangeReceiveTime && '' != daterangeReceiveTime) {
    queryParams.value.params["beginReceiveTime"] = daterangeReceiveTime.value[0];
    queryParams.value.params["endReceiveTime"] = daterangeReceiveTime.value[1];
  }
  listOrder(queryParams.value).then(response => {
    orderList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: undefined,
    orderSn: undefined,
    payId: undefined,
    memberId: undefined,
    memberUsername: undefined,
    totalAmount: undefined,
    purchasePrice: undefined,
    payAmount: undefined,
    freightAmount: undefined,
    payType: undefined,
    status: undefined,
    aftersaleStatus: undefined,
    deliveryCompany: undefined,
    deliverySn: undefined,
    autoConfirmDay: undefined,
    receiverName: undefined,
    receiverPhone: undefined,
    receiverPostCode: undefined,
    receiverProvince: undefined,
    receiverCity: undefined,
    receiverDistrict: undefined,
    receiverProvinceId: undefined,
    receiverCityId: undefined,
    receiverDistrictId: undefined,
    receiverDetailAddress: undefined,
    note: undefined,
    merchantNote: undefined,
    confirmStatus: undefined,
    deleteStatus: undefined,
    paymentTime: undefined,
    deliveryTime: undefined,
    receiveTime: undefined,
    createBy: undefined,
    createTime: undefined,
    updateBy: undefined,
    updateTime: undefined
  };
  proxy.resetForm("orderRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangePaymentTime.value = [];
  daterangeDeliveryTime.value = [];
  daterangeReceiveTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加订单管理";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  loading.value = true
  reset();
  const _id = row.id || ids.value
  getOrder(_id).then(response => {
    loading.value = false;
    form.value = response.data;
    open.value = true;
    title.value = "修改订单管理";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["orderRef"].validate(valid => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id != null) {
        updateOrder(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        }).finally(() => {
          buttonLoading.value = false;
        });
      } else {
        addOrder(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        }).finally(() => {
          buttonLoading.value = false;
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除订单管理编号为"' + _ids + '"的数据项？').then(function() {
    loading.value = true;
    return delOrder(_ids);
  }).then(() => {
    loading.value = true;
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  }).finally(() => {
    loading.value = false;
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('oms/order/export', {
    ...queryParams.value
  }, `order_${new Date().getTime()}.xlsx`)
}

getList();
</script>
